package com.lmqb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lmqb.bean.SysUser;
import com.lmqb.entry.MenuTitle;
import com.lmqb.page.CreditCheckPager;
import com.lmqb.page.HitsPager;
import com.lmqb.page.LoanPager;
import com.lmqb.page.UserTokenPager;
import com.lmqb.service.CreditService;
import com.lmqb.service.JiaoYanService;

@Controller
public class LoanController extends BaseController{

	@Autowired
	private JiaoYanService jiaoYanService;
	
	@Autowired
	private CreditService creditService;
	
	//借款列表
	@RequestMapping(value="loan.html",method=RequestMethod.GET)
	public String toLatefee(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LoanPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LoanPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			
			LoanPager userBankPager=creditService.selectLoanPager(pagerModel);
			request.setAttribute(pager, userBankPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "loanList";
	}
	
	//材料审核、复审
	@RequestMapping(value="cailiao.html",method=RequestMethod.GET)
	public String toCaiLiao(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,CreditCheckPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(CreditCheckPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			CreditCheckPager userBankPager=creditService.selectAllCredit(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userBankPager);
			request.setCharacterEncoding("utf-8");
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("借款管理");
			if(pagerModel.getType().intValue()==1){
				menuTitle.setMenu("材料审核");
			}else if(pagerModel.getType().intValue()==2){
				menuTitle.setMenu("复审列表");
			}else if(pagerModel.getType().intValue()==3){
				menuTitle.setMenu("用户额度");
			}
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "cailiaoList";
	}
	
	//放款列表
	@RequestMapping(value="fangkuan.html",method=RequestMethod.GET)
	public String toFangKuan(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LoanPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LoanPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			pagerModel.setPayStatus((byte)1);
			LoanPager userBankPager=creditService.selectAllPager(pagerModel);
			System.out.println(userBankPager.getList());
			setIfEndty(pagerModel);
			request.setAttribute(pager, userBankPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("借款管理");
			menuTitle.setMenu("放款列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "fangkuanList";
	}
	
	//打款列表
	@RequestMapping(value="hitsList.html",method=RequestMethod.GET)
	public String toHitsList(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,HitsPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(HitsPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			HitsPager userBankPager=creditService.selectDaKuan(pagerModel);
	        setIfEndty(pagerModel);
			request.setAttribute(pager, userBankPager);
			System.out.println("*************");
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("打款管理");
			if(pagerModel.getPayStatus().intValue()==1){
				menuTitle.setMenu("打款列表");
			}else if(pagerModel.getPayStatus().intValue()==2){
				menuTitle.setMenu("系统打款");
			}
			
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "hitsList";
	}
}
